﻿using Microsoft.AspNetCore.Http;
using Ocelot.Middleware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;

namespace Brc_DSB.GetWay.Extention
{
    public static class ListExtentions
    {
        public static Dictionary<string, IEnumerable<string>> ToDictionary(this List<Header> list)
        {
            var dic = new Dictionary<string, IEnumerable<string>>();
            if (list != null && list.Any())
            {
                list.ForEach(i =>
                {
                    dic.Add(i.Key, i.Values);
                });
            }
            return dic;

        }
        public static Dictionary<string, IEnumerable<string>> ToDictionary(this HttpContentHeaders headers)
        {
            var dic = new Dictionary<string, IEnumerable<string>>();
            if (headers != null)
            {
                foreach (var item in headers)
                {
                    dic.Add(item.Key, item.Value);
                }
            }
            return dic;

        }
        public static object[] ToObjectArray(this IFormCollection form)
        {
            if(form == null)
            {
                return null;
            }
            var array = new List<object>();
            foreach(var item in form)
            {
                array.Add(item.Value.ToString());
            }
            return array.ToArray();
        }

        
    }
}
